package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Objects;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TabWalletGame;
import com.ruoyi.system.service.ITabWalletGameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 钱包游戏管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-09
 */
@Controller
@RequestMapping("/system/game")
public class TabWalletGameController extends BaseController
{
    private String prefix = "system/game";

    @Autowired
    private ITabWalletGameService tabWalletGameService;

    @RequiresPermissions("system:game:view")
    @GetMapping()
    public String game()
    {
        return prefix + "/game";
    }

    /**
     * 查询钱包游戏管理列表
     */
    @RequiresPermissions("system:game:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TabWalletGame tabWalletGame)
    {
        startPage();
        List<TabWalletGame> list = tabWalletGameService.selectTabWalletGameList(tabWalletGame);
        return getDataTable(list);
    }

    /**
     * 导出钱包游戏管理列表
     */
    @RequiresPermissions("system:game:export")
    @Log(title = "钱包游戏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TabWalletGame tabWalletGame)
    {
        List<TabWalletGame> list = tabWalletGameService.selectTabWalletGameList(tabWalletGame);
        ExcelUtil<TabWalletGame> util = new ExcelUtil<TabWalletGame>(TabWalletGame.class);
        return util.exportExcel(list, "钱包游戏管理数据");
    }

    /**
     * 新增钱包游戏管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存钱包游戏管理
     */
    @RequiresPermissions("system:game:add")
    @Log(title = "钱包游戏管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TabWalletGame tabWalletGame)
    {
        return toAjax(tabWalletGameService.insertTabWalletGame(tabWalletGame));
    }

    /**
     * 修改钱包游戏管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TabWalletGame tabWalletGame = tabWalletGameService.selectTabWalletGameById(id);
        mmap.put("tabWalletGame", tabWalletGame);
        return prefix + "/edit";
    }

    @GetMapping("/getByWalletAddress/{walletAddress}")
    @ResponseBody
    public AjaxResult getByWalletAddress(@PathVariable("walletAddress") String walletAddress)
    {
        TabWalletGame tabWalletGame = tabWalletGameService.selectByWalletAddress(walletAddress);
        if(Objects.nonNull(tabWalletGame)) {
            tabWalletGame.setExpireTimeLong(tabWalletGame.getExpireTime().getTime());
        }
        return success(tabWalletGame);
    }

    /**
     * 修改保存钱包游戏管理
     */
    @RequiresPermissions("system:game:edit")
    @Log(title = "钱包游戏管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TabWalletGame tabWalletGame)
    {
        return toAjax(tabWalletGameService.updateTabWalletGame(tabWalletGame));
    }

    /**
     * 删除钱包游戏管理
     */
    @RequiresPermissions("system:game:remove")
    @Log(title = "钱包游戏管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tabWalletGameService.deleteTabWalletGameByIds(ids));
    }
}
